//
//  DetailViewController.m
//  TabNav
//
//  Created by Kalyan Mudumbai on 8/28/10.
//  Copyright 2010 GOLDMAN SACHS. All rights reserved.
//

#import "DetailViewController.h"


@implementation DetailViewController
@synthesize imageView;
@synthesize shortDescription;
@synthesize longDescription;
@synthesize nameLabel;
@synthesize scrollView;
@synthesize nameData;

//@synthesize detailWebView;
@synthesize nameId;

-(void) viewDidLoad {
	
	NSUInteger nameNumber = [[nameData objectForKey:@"no"] intValue];	
	NSString * fileName = [NSString stringWithFormat:@"%d",nameNumber];
	NSLog(@"File name is: %@.plist", fileName);
	
	NSBundle * bundle = [NSBundle mainBundle];
	NSString * plistPath = [bundle pathForResource:fileName ofType:@"plist"];
	NSLog(@"plist path is: %@", plistPath);
	
	NSDictionary * detailData = [[NSDictionary alloc] initWithContentsOfFile:plistPath] ;

	NSString * imageName = (NSString*)[detailData objectForKey:@"img"];
	NSLog(@"Image name is: %@",imageName);
	if([imageName isEqualToString:@"None"]) {
		imageName = @"main.jpg";
	}
	
	UIImage * image = [UIImage imageNamed:imageName];
	UIImageView * iv = [[UIImageView alloc] initWithImage:image];
	
	
	self.imageView.image = image;
	self.nameLabel.text = [nameData objectForKey:@"name"];
	self.shortDescription.text = [nameData objectForKey:@"sd"];
	self.longDescription.text = [detailData objectForKey:@"ld"];
	
	CGSize size = [[detailData objectForKey:@"ld"] sizeWithFont:[UIFont systemFontOfSize:14]
											  constrainedToSize: CGSizeMake(315, 10000)
												  lineBreakMode: UILineBreakModeWordWrap];
	[longDescription setFont:[UIFont systemFontOfSize:14]];
	[longDescription setFrame:CGRectMake(0, 200, size.width, size.height+10)];
	
	scrollView.pagingEnabled = YES;
	scrollView.bounces = YES;
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, 200+size.height+200);
	scrollView.delegate = self;
	
	[image release];
	[iv release];
}

-(void) viewDidUnload {
	self.imageView = nil;
	self.shortDescription = nil;
	self.longDescription = nil;
	self.nameLabel = nil;
	self.nameData = nil;
//	self.detailWebView = nil;
	[super viewDidUnload];
}

-(void) dealloc {
	[imageView release];
	[shortDescription release];
	[longDescription release];
	[nameLabel release];
	[nameData release];
//	[detailWebView release];
	[super dealloc];
}

//	UITextView * ld = [[UITextView alloc] init];
//	ld.font = [UIFont fontWithName:@"Times New Roman" size:20];
//	ld.autoresizingMask = UIViewAutoresizingFlexibleHeight;
//	[ld sizeToFit];
//	ld.editable = NO;

//	CGSize size = [msg sizeWithFont:[UIFont systemFontOfSize:14]
//				  constrainedToSize:CGSizeMake(100, 5000)
//					  lineBreakMode:UILineBreakModeWordWrap];
//	[ld setFont:[UIFont systemFontOfSize:14]];
//	[ld setFrame:CGRectMake(5, 250, 280, size.height+10)];
//	ld.text = msg;
//	self.longDescription = ld;

//	NSString *path = [[NSBundle mainBundle] pathForResource:@"detail" ofType:@"html"];
//	NSLog(@"Path of the file is %@",path);
//	NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
//	NSString *htmlString = [[NSString alloc] initWithData: [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
//	NSLog(@"Loaded html %@", htmlString);
//
//	
//	NSString * anotherPath = [[NSBundle mainBundle] bundlePath];
//	NSLog(@"bundle path is %@", anotherPath);
//	NSURL * baseUrl = [NSURL fileURLWithPath:anotherPath];
//	
//	[detailWebView loadHTMLString:htmlString baseURL:baseUrl];	
//	[self.view addSubview:webView];
//	[path release];
//	[readHandle release];
//	[htmlString release];
//	[webView release];

@end
